package com.luci.security.support;

import com.luci.security.result.DefaultAuthResult;
import com.luci.security.result.JwtUser;
import com.luci.security.result.LoginException;
import java.util.ArrayList;
import java.util.List;
import lombok.extern.slf4j.Slf4j;

/**
 * 默认ILogin实现
 *
 * @author yuyanan
 * @version 1.0
 * @date 18-11-22
 */
@Slf4j
public class DefaultLogin extends AbstractLoginAdapter<DefaultLoginBo> {

    @Override
    public Class<DefaultLoginBo> getLoginBoClass() {
        return DefaultLoginBo.class;
    }

    @Override
    public JwtUser login(DefaultLoginBo param) throws LoginException {
        if (param.getUsername() == null || param.getPassword() == null) {
            throw new LoginException(new DefaultAuthResult(409, "用户名/密码 不能为空"));
        }
        if ("admin".equals(param.getUsername()) && "admin".equals(param.getPassword())) {
            List<String> roles = new ArrayList<>();
            roles.add("admin");
            JwtUser jwtUser = new JwtUser();
            jwtUser.setRoles(roles);
            jwtUser.setDetails(param);
            return jwtUser;
        }
        throw new LoginException (new DefaultAuthResult(409, "用户名/密码 不正确"));
    }
}
